import { configureStore } from '@reduxjs/toolkit'
import counterReducer from './counterSlice'
import userInfoReducer from './userInfoSlice'
import componentReducer from './componentsReducer'
import pageInfoReducer from './pageInfoReducer'
import undoable, { excludeAction } from 'redux-undo'

const store = configureStore({
  reducer: {
    counter: counterReducer,
    userInfo: userInfoReducer,
    pageInfo: pageInfoReducer,
    // 使用undoable包裹想要实现撤回的reduce
    components: undoable(componentReducer, {
      // 限制历史记录最多 20 步
      limit: 20,
      // 过滤不需要记录的操作（如选中组件）
      filter: excludeAction([
        'components/changeSelectedId',
        'components/selectPrevComponent',
        'components/selectNextComponent',
        'components/resertComponents'
      ]),
      // 自定义undo类型,防止和其他的reduce冲突
      undoType: 'ComponentUndo',
      redoType: 'ComponentRedo'
    })
  }
})

type GetStateFunType = typeof store.getState

export type RootState = ReturnType<GetStateFunType> // 定义TS类型，使用时出现提示

export default store
